package cn.mw.cmdb.param;

import cn.hutool.core.util.StrUtil;
import cn.mw.cmdb.entity.AlgorithmInfo;
import cn.mw.cmdb.service.ServiceChoose;
import cn.mw.cmdb.service.impl.AlgorithmInfoServiceImpl;
import cn.mw.cmdb.util.CMDBTool;
import cn.mw.components.mongodb.entity.SearchParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.domain.Sort;

@EqualsAndHashCode(callSuper = true)
@Data
public class AlgorithmSearchParam extends SearchParam implements ServiceChoose, SearchParamConvert {

    // 类型字段，可选值为'繁忙度[busyness] 可用性[availability] 健康度[healthiness]'
    @Schema(description = "繁忙度[busyness] 可用性[availability] 健康度[healthiness]")
    private String type;

    @Schema(description = "算法名")
    private String algorithmName;

    private String sortName;

    // ASC | DESC
    private String sortOrder;

    @Override
    public void convert() {

    }

    @Override
    public String getServiceId() {
        return AlgorithmInfoServiceImpl.ID;
    }

    public Sort getSort() {
        //Sort by = Sort.by(Sort.Direction.DESC, CMDBTool.getFieldName(AlgorithmInfo::getCreateTime));
        if (StrUtil.isBlank(sortName)) {
            String fieldName = CMDBTool.getFieldName(AlgorithmInfo::getCreateTime);
            return Sort.by(Sort.Direction.DESC, fieldName);
        }
        return Sort.by(sortOrder, sortName);
    }
}
